/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ekuma.epos.datalogic.define.dao;

import e.odbo.data.dao.ModifiedLogDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.sqlbuilder.QBFBuilder;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteBasic;

import com.openbravo.data.loader.sentence.StaticSentence;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.format.Formats;
import com.openbravo.bean.Rant;
import com.openbravo.data.model.Field;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class RantDAO extends ModifiedLogDAO<Rant> {

    public RantDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                "RANT",
                new Field[]{
                    new Field("ID", Datas.STRING, Formats.STRING),
                    new Field("PRODUCT_ID", Datas.STRING, Formats.STRING),
                    new Field("ATTRIBUTESET_ID", Datas.BOOLEAN, Formats.BOOLEAN),
                    new Field("CUSTOMER_ID", Datas.STRING, Formats.STRING),
                    new Field("RANTPRICE", Datas.DOUBLE, Formats.CURRENCY),
                    new Field("RANTCYCLESTYLE", Datas.STRING, Formats.STRING),
                    new Field("CUSTOMDATE", Datas.INT, Formats.INT),
                    new Field("CYCLEPRICE", Datas.DOUBLE, Formats.CURRENCY),
                    new Field("EXEMPTDATE",Datas.INT, Formats.INT),
                    new Field("PRICERATE", Datas.DOUBLE,  Formats.PERCENT),
                    new Field("RANTDATA", Datas.TIMESTAMP, Formats.TIMESTAMP),
                    new Field("RETURNDATA", Datas.TIMESTAMP, Formats.TIMESTAMP),
                    new Field("MEMO", Datas.STRING, Formats.STRING),
                    new Field("RANTSTATE", Datas.STRING, Formats.STRING)
                },
                new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, Rant obj) throws BasicException {
        dp.setString(1, obj.getId());
        dp.setString(2, obj.getM_sId());
        dp.setString(3, obj.getM_sName());
        dp.setString(4, obj.getAttributeSetid());
        dp.setString(5, obj.getCustomerid());
        dp.setDouble(6, obj.getRantPrice());
        dp.setString(7, obj.getRantCycleStyle());
        dp.setInt(8, obj.getCustomDate());
        dp.setDouble(9, obj.getCyclePrice());
        dp.setInt(10, obj.getExemptDate());
        dp.setDouble(11, obj.getPriceRate());
        dp.setTimestamp(12, obj.getRantData());
        dp.setTimestamp(13, obj.getReturnData());
        dp.setString(14, obj.getMemo());
        dp.setString(15, obj.getRantState());
    }

    public Rant readValues(DataRead dr,Rant r) throws BasicException {
        Date time = null;
        if(r==null)
        	r = new Rant();
        r.setId(dr.getString(1));
        r.setM_sId(dr.getString(2));
        r.setM_sName(dr.getString(3));
        r.setAttributeSetid(dr.getString(4));
        r.setCustomerid(dr.getString(5));
        r.setRantPrice(dr.getDouble(6));
        r.setRantCycleStyle(dr.getString(7));
        r.setCustomDate(dr.getInt(8));
        r.setCyclePrice(dr.getDouble(9));
        r.setExemptDate(dr.getInt(10));
        r.setPriceRate(dr.getDouble(11));
        r.setRantData(dr.getTimestamp(12));
        time = dr.getTimestamp(13);
        if (time != null) {
            r.setReturnData(time);
        }
        r.setMemo(dr.getString(14));
        r.setRantState(dr.getString(15));
        return r;
    }

	public List<Rant> list(Object filter) throws BasicException {
		return new StaticSentence(s, new QBFBuilder(
                "SELECT PP.ID,PP.PRODUCT_ID, P.NAME, PP.ATTRIBUTESET_ID, PP.CUSTOMER_ID, PP.RANTPRICE, PP.RANTCYCLESTYLE, PP.CUSTOMDATE, PP.CYCLEPRICE, PP.EXEMPTDATE, PP.PRICERATE, PP.RANTDATA, PP.RETURNDATA, PP.MEMO, PP.RANTSTATE  "
                + "FROM RANT PP, PRODUCTS P  WHERE PP.PRODUCT_ID=P.ID AND ?(QBF_FILTER)", new String[]{"PP.PRODUCT_ID", "PP.CUSTOMER_ID", "PP.RANTSTATE"}), new SerializerWriteBasic(Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING), this).list(filter);
	}

	@Override
    public Class getSuportClass() {
        return Rant.class;
    }
}
